package pr.iceworld.fernando.commonbase.model;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public enum  TimePeriod implements BaseValue, ModelBase {
    /**
     * morning
     */
    M(0),
    /**
     * afternoon
     */
    A(1),
    /**
     * evening
     */
    E(2);

    private static Map<Integer, TimePeriod> valueMap = new HashMap<>();

    static {
        for(TimePeriod timePeriod : TimePeriod.values()) {
            valueMap.put(timePeriod.value, timePeriod);
        }
    }

    private int value;
    TimePeriod(int value) { this.value = value; }

    @Override
    public int getValue() { return this.value; }

    public static TimePeriod getByValue(int value) {
        TimePeriod result = valueMap.get(value);
        if(Objects.isNull(result)) {
            throw new IllegalArgumentException("No element matches " + value);
        }
        return result;
    }
}
